home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_ddd.idb / usr / freeware / share / ddd-3.3.1 / vsllib / tab.vsl.z / tab.vsl
Text File  |  2001-10-09  |  4KB  |  127 lines

  1. // $Id: tab.vsl,v 1.2 2000/06/09 13:06:28 andreas Exp $
  2. // Tables
  3.  
  4. // Copyright (C) 1993 Technische Universitaet Braunschweig, Germany.
  5. // Written by Andreas Zeller <zeller@gnu.org>.
  6. // 
  7. // This file is part of DDD.
  8. // 
  9. // DDD is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. // 
  14. // DDD is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. // See the GNU General Public License for more details.
  18. // 
  19. // You should have received a copy of the GNU General Public
  20. // License along with DDD -- see the file COPYING.
  21. // If not, write to the Free Software Foundation, Inc.,
  22. // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. // 
  24. // DDD is the data display debugger.
  25. // For details, see the DDD World-Wide-Web page, 
  26. // `http://www.gnu.org/software/ddd/',
  27. // or send a mail to the DDD developers <ddd@gnu.org>.
  28.  
  29. #include "std.vsl"
  30.  
  31. // Version
  32. tab_version() = "$Id: tab.vsl,v 1.2 2000/06/09 13:06:28 andreas Exp $";
  33.  
  34. // Table functions
  35.  
  36. // tab([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) results in
  37. // 1 2 3
  38. // 4 5 6
  39. // 7 8 9
  40.  
  41. // tab([[1, 2, 3], [4, 5, 6], 7]]) results in
  42. // 1 2 3
  43. // 4 5 6
  44. // 7
  45.  
  46. // Override this one to create an alternative padding
  47. tab_elem([]) = tab_elem(0);
  48. tab_elem(x)  = whiteframe(x);
  49.  
  50. // Subroutines
  51.  
  52. // Maximum width and height of a list
  53. _tab_maxhspace([...]) = hspace(valign(...));
  54. _tab_maxvspace([...]) = vspace(halign(...));
  55.  
  56. // Check if list is empty
  57. _tab_allempty([[]]) = true;
  58. _tab_allempty([[] : more]) = _tab_allempty(more);
  59. _tab_allempty([_...]) = false;
  60.  
  61. // Create a list from the heads of all elems
  62. _tab_heads([]) = [];
  63. _tab_heads([[head : _] : more]) =
  64.     [tab_elem(head) : _tab_heads(more)];
  65. _tab_heads([x]) = [tab_elem(x)];
  66.  
  67. // Create a list from the tails of all elems
  68. _tab_tails([]) = [];
  69. _tab_tails([[_ : tail] : more]) =
  70.     [tail : _tab_tails(more)];
  71. _tab_tails(_) = [];
  72.  
  73. // Create a list with column widths
  74. _tab_width(...) =
  75.     if _tab_allempty(...) 
  76.     then []
  77.     else [ _tab_maxhspace(_tab_heads(...)) : _tab_width(_tab_tails(...)) ] 
  78.     fi;
  79.  
  80. // Align a line with given column widths
  81. _tab_line([width], [head]) =
  82.   width | tab_elem(head);
  83. _tab_line([width : twidth], [head : tail]) =
  84.   _tab_line([width], [head]) & _tab_line(twidth, tail);
  85. _tab_line([width], x) =
  86.   _tab_line([width], [x]);
  87. _tab_line([width : twidth], x) =
  88.   _tab_line([width], [x]) & _tab_line(twidth, 0);
  89.  
  90. // Align a line with given column widths, using delimiters
  91. _dtab_line([width], [head]) =
  92.   width | tab_elem(head);
  93. _dtab_line([width : twidth], [head : tail]) =
  94.   _dtab_line([width], [head]) & vrule() & _dtab_line(twidth, tail);
  95. _dtab_line([width], x) =
  96.   _tab_line([width], [x]);
  97. _dtab_line([width : twidth], x) =
  98.   _tab_line([width], [x]) & vwhite(rulethickness()) & _dtab_line(twidth, 0);
  99.  
  100. // Create a table with given column widths
  101. _tab(width, [head]) =
  102.   _tab_line(width, head);
  103. _tab(width, [head : tail]) =
  104.   _tab_line(width, head)
  105. | _tab(width, tail);
  106.  
  107. // Create a table with delimiters and given column widths
  108. _dtab(width, [head]) =
  109.   vrule() & _dtab_line(width, head) & vrule();
  110. _dtab(width, [head : tail]) =
  111.   vrule() & _dtab_line(width, head) & vrule()
  112. | hrule()
  113. | _dtab(width, tail);
  114.  
  115.  
  116. // Public functions
  117.  
  118. // Create a table, calculating the maximum width
  119. tab(...) =
  120.   _tab(_tab_width(...), ...);
  121.  
  122. // Same, but with delimiters
  123. dtab(...) =
  124.   hrule()
  125. | _dtab(_tab_width(...), ...)
  126. | hrule();
  127.